//
//  NotFindDeviceView.m
//  jingdongfang
//
//  Created by LJL on 2017/9/6.
//  Copyright © 2017年 BOE. All rights reserved.
//

#import "NotFindDeviceView.h"
#import "KLCPopup.h"

@interface NotFindDeviceView ()
{
    UILabel *textL;
    UILabel *titleL;
    UIButton *bangdingBtn;
    UIButton *cancelBtn;
}
@end

@implementation NotFindDeviceView

+ (NotFindDeviceView *)showNotFindDeviceView {
    NotFindDeviceView *noFindView = [[NotFindDeviceView alloc] initWithFrame:CGRectMake(0, 0, 220, 240)];
    noFindView.backgroundColor = [UIColor whiteColor];
    noFindView.layer.masksToBounds = YES;
    noFindView.layer.cornerRadius = 5;
    noFindView.layer.borderColor = [UIColor lightGrayColor].CGColor;
    noFindView.layer.borderWidth = 1.0;
    [noFindView show];
    return noFindView;
}

- (void)show {
    KLCPopup *pop = [KLCPopup popupWithContentView:self showType:KLCPopupShowTypeSlideInFromTop dismissType:KLCPopupDismissTypeSlideOutToBottom maskType:KLCPopupMaskTypeDimmed dismissOnBackgroundTouch:YES dismissOnContentTouch:NO];
    [pop show];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame])
    {
        [self loadUI];
    }
    return self;
}

- (void)loadUI
{
    self.backgroundColor = [UIColor c4Color];
    
    textL = [[UILabel alloc] init];
    textL.font = [UIFont boldSystemFontOfSize:18];
    textL.textAlignment = NSTextAlignmentCenter;
    textL.backgroundColor = [UIColor whiteColor];
    textL.textColor = [UIColor c4Color];
//    textL.text = @"没有找到设备";
    textL.text = NSLocalizedString(@"No Devices Found", nil);
    [self addSubview:textL];
    
    titleL = [[UILabel alloc] init];
    titleL.font = [UIFont systemFontOfSize:16];
    titleL.numberOfLines = 0;
    titleL.textAlignment = NSTextAlignmentCenter;
    titleL.backgroundColor = [UIColor whiteColor];
    titleL.textColor = [UIColor c4Color];
//    titleL.text = @"您还没有绑定任何设备, 无法完成推送";
    titleL.text = NSLocalizedString(@"Link iGallery device first!", nil);
    [self addSubview:titleL];
    
    bangdingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [bangdingBtn setTitle:@"立即绑定" forState:UIControlStateNormal];
//    [bangdingBtn setTitle:@"立即绑定" forState:UIControlStateHighlighted];
    [bangdingBtn setTitle:NSLocalizedString(@"Link Now !", nil) forState:UIControlStateNormal];
    [bangdingBtn setTitle:NSLocalizedString(@"Link Now !", nil) forState:UIControlStateHighlighted];
    [bangdingBtn setTitleColor:[UIColor appColor] forState:UIControlStateNormal];
    [bangdingBtn setTitleColor:[UIColor appColor] forState:UIControlStateHighlighted];
    bangdingBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [bangdingBtn addTarget:self action:@selector(bangdingBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:bangdingBtn];

    cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [cancelBtn addTarget:self action:@selector(cancelBtnClick) forControlEvents:UIControlEventTouchUpInside];
    cancelBtn.layer.cornerRadius = 20;
    cancelBtn.layer.masksToBounds = YES;
    cancelBtn.backgroundColor = [UIColor clearColor];
    [cancelBtn setImage:[UIImage imageNamed:@"circle-拷贝"] forState:UIControlStateNormal];
    [cancelBtn setImage:[UIImage imageNamed:@"circle-拷贝"] forState:UIControlStateHighlighted];
    [self addSubview:cancelBtn];
    
    [textL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(35);
        make.height.mas_equalTo(20);
    }];
    
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.top.mas_equalTo(textL.mas_bottom).mas_offset(35);
        make.height.mas_equalTo(40);
    }];
    
    [bangdingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.top.mas_equalTo(titleL.mas_bottom).mas_offset(40);
        make.height.mas_equalTo(20);
    }];
    
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.right.mas_equalTo(-5);
        make.width.height.mas_equalTo(40);
    }];
}

- (void)bangdingBtnClick
{
    self.bangdingBlock();
    [KLCPopup dismissAllPopups];
}

- (void)cancelBtnClick
{
    [KLCPopup dismissAllPopups];
}

@end
